//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
let extension = {
  components: {//动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: '',//{ template: "<div>扩展组xx件</div>" },
    gridBody: '',
    gridFooter: '',
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: '',
    modelBody: '',
    modelFooter: ''
  },
  buttons: { view: [], box: [], detail: [] },//扩展的按钮
  methods: {//事件扩展
    onInit () {
      // label宽度
      this.boxOptions.labelWidth = 140
      // 弹框宽度
      this.boxOptions.width = 1000
      // 弹框高度
      this.boxOptions.height = 500
      // 开启单选
      //;
      // 内容超出后自动换行
      this.textInline = true;
      // 不显示多选框
      //;
      // 显示序号
      //;
      // 控制佣金类型选择
      let commission_type = this.getFormOption("commission_type");//佣金类型
      commission_type.onChange = (val, item) => {
        this.changeCommissionType(val)
      }
      // 控制升级条件选择
      let condition = this.getFormOption("condition");//升级条件
      condition.onChange = (val, item) => {
        this.changeCondition(val, item)
      }
    },
    // 控制佣金类型选择
    changeCommissionType (val, see) {
      console.log("佣金类型", val);
      if (!see) {
        this.editFormFields.commission_rate_1st = ""
        this.editFormFields.commission_rate_2nd = ""
        this.editFormFields.commission_rate_3rd = ""
        this.editFormFields.commission_amount_1st = ""
        this.editFormFields.commission_amount_2nd = ""
        this.editFormFields.commission_amount_3rd = ""
      }
      // val =1 固定金额  val=2 固定比例
      let commission_rate_1st = this.getFormOption("commission_rate_1st");//1级佣金比列
      let commission_rate_2nd = this.getFormOption("commission_rate_2nd");//2级佣金比列
      let commission_rate_3rd = this.getFormOption("commission_rate_3rd");//3级佣金比列
      let commission_amount_1st = this.getFormOption("commission_amount_1st");//1级佣金金额
      let commission_amount_2nd = this.getFormOption("commission_amount_2nd");//2级佣金金额
      let commission_amount_3rd = this.getFormOption("commission_amount_3rd");//3级佣金金额
      this.$set(commission_rate_1st, "hidden", val == 2 ? false : true)
      this.$set(commission_rate_2nd, "hidden", val == 2 ? false : true)
      this.$set(commission_rate_3rd, "hidden", val == 2 ? false : true)
      this.$set(commission_amount_1st, "hidden", val == 1 ? false : true)
      this.$set(commission_amount_2nd, "hidden", val == 1 ? false : true)
      this.$set(commission_amount_3rd, "hidden", val == 1 ? false : true)
    },
    // 控制升级条件选择 17
    async changeCondition (val, item, see) {
      console.log("升级条件", val, item, see);
      // 将全部隐藏
      await item.data.forEach(ele => {
        if (val.indexOf(ele.key) == "-1") {
          this.editFormFields[ele.key] = ""
        }
        let caseData = this.getFormOption(ele.key);
        this.$set(caseData, "hidden", true)
      })
      // 将选中数据显示
      val.forEach(ele => {
        let caseData = this.getFormOption(ele);
        this.$set(caseData, "hidden", false)
        // console.log("aaaa", caseData);
      })
      console.log("aaa", this.editFormOptions, this.editFormFields);
    },
    // 点击编辑/新建按钮弹出框前
     async modelOpenBeforeAsync (row) {
    //   console.log("编辑1", row, this.$refs.table.rowData);
      let sortList = this.$refs.table.rowData
    //   let share_lever_sort = this.getFormOption("share_lever_sort");//等级
    //   await share_lever_sort.data.forEach(item => {
    //     sortList.forEach(ele => {
    //       if (item.key == ele.share_lever_sort) {
    //         item.hidden = true
    //       }
    //     })
    //   })
       return true
    },
    // 点击编辑/新建按钮弹出框后
    async modelOpenAfter (row) {
      console.log("编辑", row, this.$refs.table.rowData);
      if (this.currentAction == "Add") {

      } else {
        // 控制佣金类型选择
        this.changeCommissionType(row.commission_type, true)
        let condition = this.getFormOption("condition");//升级条件
        console.log("查看", condition.data);
        this.changeCondition(row.condition.split(","), condition, 123)
      }
    },
    addBefore (formData) { //新建保存前formData为对象，包括明细表
      return this.veriFromTable(formData)
    },
    updateBefore (formData) { //编辑保存前formData为对象，包括明细表、删除行的Id
      return this.veriFromTable(formData)
    },
    // 保存前编辑 
    veriFromTable (formData) {
      console.log("保存前编辑", formData);
      if (!formData.mainData.condition) {
        this.$message.error("数据验证未通过！")
        return false
      }
      return true
    },
    // 循环表单并返回数据
    getFormOption (field) {
      let option;
      this.editFormOptions.forEach(x => {
        x.forEach(item => {
          if (item.field == field) {
            option = item;
          }
        })
      })
      return option;
    },
    rowClick ({ row, column, event }) { //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },

  }
};
export default extension;